home *** CD-ROM | disk | FTP | other *** search
- Path: news.gulfaero.com!not-for-mail
- From: swofford@voyager.eng.gulfaero.com (Van Swofford)
- Newsgroups: comp.lang.c
- Subject: Re: string search?
- Date: 27 Mar 1996 14:52:46 -0500
- Organization: Gulfstream Aerospace Corporation, Savannah Georgia USA
- Message-ID: <4jc6ae$eol@voyager.eng.gulfaero.com>
- NNTP-Posting-Host: voyager.eng.gulfaero.com
-
- Ricardo Mor <rmor1@ix.netcom.com> wrote:
- > How can I search for a string of characters within another string?
- >for example..
- >
- > string = "NEXT_TIME";
- >
- > string2 = "NEXT";
- >
- > how can I find string2 in string?
- >
- >
- >Eddy...
-
-
- Try:
-
- #include <string.h>
-
- char string[] = "NEXT_TIME";
- char string2[] = "NEXT";
- char *ptr;
- int position;
-
- ptr = strstr (string, string2);
- position = ptr - string; /* first char position in string would be 0 */
-
- The Microsoft C documentation indicates that strstr is ANSI compliant,
- but not available under UNIX.
-
- Hope this helps.
- Van
- --
-
- ______________________________________________________________________________
- "Half of what I say is meaningless....." - John Lennon
- Your job, should you choose to accept it, is to determine which half.
-